import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
import 'package:leader_doctor_flutter/common/widget/comm_widget.dart';
import '../router/router.dart';

/// @Author lixiaobin
/// @Date 2023/11/3
/// @Description
class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  var arr = <Data>[];

  @override
  void initState() {
    super.initState();
    for (var value in appRouter.routeConfiguration.routes) {
      if (value is GoRoute) {
        var path = value.path;
        switch (path) {
          //交易详情
          case PageUrl.walletIncomeDetail:
            path += '?subOrderNo=202401091012323053';
            break;
          //处方单
          case PageUrl.prescriptionPreView:
            path += '?prescriptionNo=202405151540138085';
            break;
          //咨询详情
          case PageUrl.consultationDetail:
            path += '?id=202403041744161338';
            break;
          //大图浏览
          case PageUrl.browseImage:
            arr.add(Data(value.name, path)
              ..extra = [
                'icon_alert_msg.webp',
                'icon_alert_msg.webp',
                'icon_alert_msg.webp',
              ]);
            continue;
        }
        arr.add(Data(value.name, path));
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommWidget.getCommAppbar(context),
      body: Container(
          alignment: Alignment.topCenter,
          width: double.infinity,
          height: double.infinity,
          child: GridView.count(
            shrinkWrap: true,
            childAspectRatio: 2.5,
            crossAxisCount: 3,
            mainAxisSpacing: 5.w,
            crossAxisSpacing: 5.w,
            children: arr.map((value) => _getItem(value)).toList(),
          )),
    );
  }

  Widget _getItem(Data data) {
    return GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () => context.push(data.routerUrl ?? '', extra: data.extra),
        child: Container(
            alignment: Alignment.center,
            color: Colors.blue,
            child: Text(data.name ?? '',
                style: TextStyle(
                  fontSize: 20.sp,
                  color: Colors.white,
                ))));
  }
}

class Data {
  String? name;
  String? routerUrl;
  Object? extra;

  Data(this.name, this.routerUrl);
}
